package com.ywl.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywl.pojo.Student;
import com.ywl.service.StudentService;
import com.ywl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DL5O
 * @version 1.0
 */
@Api(tags = "学生控制器")
@RestController//   不是@Controller，异步Controller
@RequestMapping("/sms/studentController")
public class StudentController {

    @Autowired
    StudentService studentService;


    @DeleteMapping("/delStudentById")
    public Result delStudentById(@ApiParam("要删除学习id的集合") @RequestBody List<Integer> ids) {
        studentService.removeByIds(ids);
        return Result.ok();
    }

    /**
     * 更新或者增加
     *
     * @param student
     * @return
     */
    @ApiOperation("更新或增加学生信息")
    @PostMapping("/addOrUpdateStudent")
    public Result addOrUpdateStudent(@RequestBody Student student) {
        studentService.saveOrUpdate(student);
        return Result.ok();
    }

    // /sms/studentController/getStudentByOpr/1/3
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result getStudentByOpr(
            @ApiParam("分页号") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页大小") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件") Student student
    ) {

        Page<Student> page = new Page<>(pageNo, pageSize);
        IPage<Student> pageRs = studentService.getStudentOpr(page, student);
        return Result.ok(pageRs);
    }
}
